package com.zhkj.txg.module.product.popup

import android.content.Context
import android.view.View
import android.view.animation.Animation
import com.zhkj.txg.R
import razerdp.basepopup.BasePopupWindow

class UpdatePopupWindow(
    context: Context,
    val onUpdate: (url: String?) -> Unit
) : BasePopupWindow(context) {

    private var url: String? = null

    init {
        setOutSideDismiss(false)
        setBackPressEnable(false)
    }

    override fun onCreateContentView(): View = createPopupById(R.layout.popup_update)
    override fun onCreateShowAnimation(): Animation = getTranslateVerticalAnimation(1f, 0f, 300)
    override fun onCreateDismissAnimation(): Animation = getTranslateVerticalAnimation(0f, 1f, 300)

    override fun onViewCreated(contentView: View?) {
        contentView?.let {
            it.findViewById<View>(R.id.bt_cancel).setOnClickListener { dismiss() }
            it.findViewById<View>(R.id.bt_confirm).setOnClickListener { onUpdate(url) }
        }
    }

    fun setData(url: String) {
        this.url = url
    }

    //强制更新
    fun setForce(enforce: Int) {
        if (enforce == 1) {
           findViewById<View>(R.id.bt_cancel).visibility = View.GONE
        }
    }
}
